//
//  StatusesTopView.swift
//  HMWeibo08
//
//  Created by 唐万超 on 15/8/3.
//  Copyright © 2015年 唐万超. All rights reserved.
//

import UIKit
import SDWebImage

class StatusesTopView: UIView {

    var statuses: Status? {
        didSet {
            //iconView.image = UIImage(named: "avatar")
            if let url = statuses?.user?.imageURL {
            
                // 设置头像
                iconView.sd_setImageWithURL(url)
                
            }
            
            // 设置会员
            memberIconView.image = statuses?.user?.memberImage
            // 设置vip
            vipIconView.image = statuses?.user?.vipImage
            
            // TODO: 待完成
            sourceLabel.text = "来自 阿姆斯特丹 的微博"
            timeLabel.text = "刚刚"
            
            nameLabel.text = statuses?.user?.name ?? ""
        }
    }
    
   override init(frame: CGRect) {
        super.init(frame: frame)
    
        setUpUI()
    }
    
 
   required init?(coder aDecoder: NSCoder) {
       fatalError("init(coder:) has not been implemented")
   }
    
    /// 搭建界面
    private func setUpUI() {
        
        let stepView = UIView()
        
        stepView.backgroundColor = UIColor(white: 0.8, alpha: 1.0)
        addSubview(stepView)
        stepView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 10))
        
        // 添加控件
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(memberIconView)
        addSubview(vipIconView)
        
        // 添加约束
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: stepView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: statusCellControlMargin, y: statusCellControlMargin))
//        iconView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 12, y: 12))
        
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: statusCellControlMargin, y: 0))
        
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: statusCellControlMargin, y: 0))
        
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: timeLabel, size: nil, offset: CGPoint(x: statusCellControlMargin, y: 0))
        
        memberIconView.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: nameLabel, size: nil, offset: CGPoint(x: statusCellControlMargin, y: 0))
        
        vipIconView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 8))
    
    }
    
    // MARK: - 懒加载控件
    // 头像图标
    private lazy var iconView: UIImageView = UIImageView()
    
    // 姓名
    private lazy var nameLabel: UILabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
    // 时间标签
    private lazy var timeLabel: UILabel = UILabel(color: UIColor.orangeColor(), fontSize: 9)
    // 来源标签
    private lazy var sourceLabel: UILabel = UILabel(color: UIColor.lightGrayColor(), fontSize: 9)
    // 会员图标
    private lazy var memberIconView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    
    // vip图标
    private lazy var vipIconView: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    

}
